//背包dp 
//二维dp
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int m=0,bagweight=0;
	cin >> m >> bagweight;
	
	vector<int> weight(m);
	for(int i = 0; i < m; i++)
		cin >> weight[i];
	
	vector<int> value(m);
	for(int i = 0; i < m; i++)
		cin >> value[i];
	
	vector<vector<int>> dp(m,vector<int>(bagweight + 1,0));
	//横向初始化
	for(int i = weight[0]; i <= bagweight; i++)
		dp[0][i] = value[0];
	//纵向初始化
	for(int i = 1; i < m; i++)
		dp[i][0] = 0;
	
	for(int i = 1; i < m; i++)
		for(int j = 1; j <= bagweight; j++)
		{
			if(j < weight[i]) dp[i][j] = dp[i-1][j];
			else dp[i][j] = max(dp[i-1][j],dp[i-1][j-weight[i]]+value[i]);
		}
	
	cout << dp[m-1][bagweight];
	return 0;
}
